home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / gs24src.zip / GDEV4081.C < prev    next >
C/C++ Source or Header  |  1991-11-27  |  3KB  |  95 lines

  1. /* Copyright (C) 1991 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* gdev4081.c */
  21. /* Ricoh 4081 laser printer driver for Ghostscript */
  22. #include "gdevprn.h"
  23.  
  24. #define X_DPI 300            /* pixels per inch */
  25. #define Y_DPI 300            /* pixels per inch */
  26.  
  27. /* The device descriptor */
  28. private dev_proc_print_page(r4081_print_page);
  29. gx_device_printer gs_r4081_device =
  30.   prn_device(prn_std_procs, "r4081",
  31.     85,                /* width_10ths, 8.5" */
  32.     110,                /* height_10ths, 11" */
  33.     X_DPI, Y_DPI,
  34.     0.25, 0.16, 0.25, 0.16,        /* margins */
  35.     1, r4081_print_page);
  36.  
  37. /* ------ Internal routines ------ */
  38.  
  39.  
  40. /* Send the page to the printer. */
  41. private int
  42. r4081_print_page(gx_device_printer *pdev, FILE *prn_stream)
  43. {    
  44.     int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
  45.     int out_size = ((pdev->width + 7) & -8) ;
  46.     byte *out = (byte *)gs_malloc(out_size, 1, "r4081_print_page(out)");
  47.     int lnum = 0;
  48.     int last = pdev->height;
  49.  
  50.     /* Check allocations */
  51.     if ( out == 0 )
  52.        {    if ( out ) gs_free(out, out_size, 1, "r4081_print_page(out)");
  53.         return -1;
  54.        }
  55.  
  56.     /* find the first line which has something to print */
  57.     while ( lnum < last )
  58.     {
  59.         gdev_prn_copy_scan_lines(pdev, lnum, (byte *)out, line_size);
  60.         if ( out[0] != 0 ||
  61.              memcmp((char *)out, (char *)out+1, line_size-1)
  62.            )
  63.             break;
  64.         lnum ++;
  65.     }
  66.  
  67.     /* find the last line which has something to print */
  68.     while (last > lnum) {
  69.         gdev_prn_copy_scan_lines(pdev, last-1, (byte *)out, line_size);
  70.         if ( out[0] != 0 ||
  71.              memcmp((char *)out, (char *)out+1, line_size-1)
  72.            )
  73.             break;
  74.         last --;
  75.     }
  76.  
  77.     /* Initialize the printer and set the starting position. */
  78.     fprintf(prn_stream,"\033\rP\033\022YB2 \033\022G3,%d,%d,1,1,1,%d@",
  79.             out_size, last-lnum, (lnum+1)*720/Y_DPI);
  80.  
  81.     /* Print lines of graphics */
  82.     while ( lnum < last )
  83.        {
  84.         gdev_prn_copy_scan_lines(pdev, lnum, (byte *)out, line_size);
  85.         fwrite(out, sizeof(char), line_size, prn_stream);
  86.         lnum ++;
  87.        }
  88.  
  89.     /* Eject the page and reinitialize the printer */
  90.     fputs("\f\033\rP", prn_stream);
  91.  
  92.     gs_free(out, out_size, 1, "r4081_print_page(out)");
  93.     return 0;
  94. }
  95.